<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/wesite/view/common/base.jsp"%>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>搜索结果</title>
    <%@ include file="/wesite/view/common/common.jsp"%>
    <link rel="stylesheet" type="text/css" href="${webctx}/css/aui-slide.css" />
    <script type="text/javascript" src="${webctx}/script/aui-tab.js" ></script>
    <script type="text/javascript" src="${webctx}/script/aui-slide.js"></script>
    <script type="text/javascript" src="${webctx}/script/aui-scroll.js"></script>
</head>
<style>
    .aui-searchbar .aui-searchbar-input{
        background-color: #f2f2f2;
    }
    .searchbox .search-no-data{
        position: fixed;
        top: 50%;
        left: 50%;
        width: 100%;
        font-size: 0;
        text-align: center;
        -webkit-transform: translate(-50%, -70%);
        -moz-transform: translate(-50%, -70%);
        -ms-transform: translate(-50%, -70%);
        -o-transform: translate(-50%, -70%);
        transform: translate(-50%, -70%);
    }
</style>
<body>
    <div class="searchbox">
        <form id="searchForm" action="/we/product/search-result" method="get">
            <input name="pageno" value="${pageno }" type="hidden">
            <input name="ordertype" value="${ordertype }" type="hidden">
            <input name="orderby" value="${orderby }" type="hidden">
            <input name="instock" value="${instock }" type="hidden">
            <div class="aui-searchbar" id="search">
                <div class="aui-searchbar-input">
                    <input type="search" placeholder="请输入城市名称或首字母" id="search-input" name="querylike" value="${querylike}">
                    <div class="aui-searchbar-clear-btn">
                    </div>
                </div>
                <div class="aui-searchbar-btn" tapmode>搜索</div>
            </div>
        </form>

        <p class="search-con-tit">共找到 <em></em> 条相关结果</p>

        <div class="product-box" id="hasProductLayout">
            <div class="content no-top-bor">

                <ul id="searchProductPanel">

                </ul>

                <div class="aui-clearfix"></div>
                <div id="searchProductHolder" style="margin: 10px 0; text-align: center;display: none; color: #999;"></div>

            </div>
        </div>

        <%--<div style="display: none;" class="search-no-data" id="noProductLayout">--%>
            <div style="display: none;" class="shopping-cart-null search-no-data"  id="noProductLayout">
                <span class="txt-kong-img"><img src="/wesite/images/Thome.png"></span>

                <p style="font-size: 18px; margin-top: 15px">什么也没找到，试试其他关键字吧</p>
            </div>
        <%--</div>--%>

    </div>
    <div class="cl"></div>

    <%request.setAttribute("bottomMenuId","search");%>
    <%@ include file="/wesite/view/common/bottom.jsp"%>

    <%@ include file="/wesite/view/common/popup-menu.jsp"%>


</body>
<script type="text/javascript">
    apiready = function(){
        api.parseTapmode();
    }
    var searchBar = document.querySelector(".aui-searchbar");
    var searchBarInput = document.querySelector(".aui-searchbar input");
    var searchBarBtn = document.querySelector(".aui-searchbar .aui-searchbar-btn");
    var searchBarClearBtn = document.querySelector(".aui-searchbar .aui-searchbar-clear-btn");
    if(searchBar){
        searchBarInput.onclick = function(){
            searchBarBtn.style.marginRight = 0;
        }
        searchBarInput.oninput = function(){
            if(this.value.length){
                searchBarClearBtn.style.display = 'block';
                searchBarBtn.classList.add("aui-text-info");
                searchBarBtn.textContent = "搜索";
            }else{
                searchBarClearBtn.style.display = 'none';
                searchBarBtn.classList.remove("aui-text-info");
                searchBarBtn.textContent = "取消";
            }
        }
    }
    searchBarClearBtn.onclick = function(){
        this.style.display = 'none';
        searchBarInput.value = '';
        searchBarBtn.classList.remove("aui-text-info");
        searchBarBtn.textContent = "取消";
    }
    searchBarBtn.onclick = function(){
        var keywords = searchBarInput.value;
        if(keywords.length){
            searchBarInput.blur();
            $("#searchForm").submit();
            return true;
        }else{
            searchBarInput.value = '';
            searchBarInput.blur();
        }
    }

    /*设置左侧高度*/
    var topbarHeight = $('header.topbar').height();
    var bottomnavHeight = $('.bottom-nav').height();
    $('.search-type-sidebar,.searchlist-con').height($(window).height()-topbarHeight*2-bottomnavHeight-15);

    /*左侧分类选中样式切换*/
    $('.search-type-sidebar li').on('click',function(){
        $(this).addClass('cur');
        $(this).siblings().removeClass('cur')
    })
</script>


<script>



    function getQueryParm(){
        var parm=new Object();
        parm.pageno=$("[name='pageno']").val();
        parm.instock=$("[name='instock']").val();
        parm.ordertype=$("[name='ordertype']").val();
        parm.orderby=$("[name='orderby']").val();
        parm.querylike=$("[name='querylike']").val();
        return parm;
    }

    var searchLoading = false;
    var nextsearchPageNo = 1;
    function loadsearch(){
        if(searchLoading){
            return false;
        }else{
            searchLoading=true;
        }
        $("#searchProductHolder").text("正在加载 ...").show();

        var parm=getQueryParm();
        $w.httpRequest({
            url:apiroot+'/we/product/loadproducts',
            data:{"pno":parm.pageno,"ordertype":parm.ordertype,"orderby":parm.orderby,"instock":parm.instock,"querylike":parm.querylike},
            ok:function(ret){
                searchLoading = false;
                var datas = ret.Data.products;
                var panel = $("#searchProductPanel");
                console.log(datas);
                $(".search-con-tit em").text(ret.Data.resultcount);

                if(nextsearchPageNo==1&&datas.length<=0){
                    $("#hasProductLayout").hide();
                    $(".search-con-tit").hide();
                    $("#noProductLayout").show();
                    nextsearchPageNo = 0;
                }
                if(datas&&datas.length>0){
                    for(var i=0;i<datas.length;i++){
                        var data=datas[i];
                        var h = "";
                        var cjia=(data.b_chanjia?data.b_chanjia:"");
                        if(cjia.length>15)cjia=cjia.substr(0,15)+"...";
                        h+=("<li id="+data.id+" onclick=\"javascript:window.location='"+ctx+"/we/product/"+data.id+"';\" >");
                        h+=("<img src='"+getRandomFileserver()+data.photo+"' onerror='this.src=\"" + ctx + "/website/images/noimg.jpg\"'>");
                        h+=("<h3>"+data.productname+' '+(data.attrname||"")+"</h3>");
                        h+=("<span class='company'>"+(cjia||"")+"</span>");
                        h += ("<span class='specifications'>" + (data.b_guige || "") + "</span>");
                        if (isuserauth && islogin && data.canbuy == "1") {
                            h +=("<span class='price'>");
                            h +=("<i class='a'>¥ "+ data.price +"</i>");
                            if(data.promotion_coupon){
                                h += ("<em>券</em>");
                            }
                            if(data.promotion_flash_sale){
                                h += ("<em>特价</em>");
                            }
                            if(data.promotion_buy_send){
                                h += ("<em>买送</em>");
                            }
                            if(data.promotion_money_off){
                                h += ("<em>满减</em>");
                            }
                            if(data.promotion_purchase_gift){
                                h += ("<em>满赠</em>");
                            }
                            if (data.promotion_flash_sale) {
                                if (!data.fs_amount) {
                                    h+=("<a  class=\"ico-shopping-cart\" href=\"javascript:; \"><img src=\"" + ctx + "/wesite/images/ico-shopping-cart-no.png\"' ></a>");
                                } else {
                                    h+=("<a onclick=\"stopBubble(event,"+data.id+")\" class=\"ico-shopping-cart\" href=\"javascript:; \"><img src=\"" + ctx + "/wesite/images/ico-shopping-cart.png\"' ></a>");
                                }
                            }else {
                                if (data.amount <= 0) {
                                    h+=("<a  class=\"ico-shopping-cart\" href=\"javascript:; \"><img src=\"" + ctx + "/wesite/images/ico-shopping-cart-no.png\"' ></a>");
                                } else {
                                    h+=("<a onclick=\"stopBubble(event,"+data.id+")\" class=\"ico-shopping-cart\" href=\"javascript:; \"><img src=\"" + ctx + "/wesite/images/ico-shopping-cart.png\"' ></a>");
                                }
                            }


                            h +=("</span>")
                        }else if (!islogin){
                            h+=("<span class='price'><i class='a'>登录可见</i></span>");
                            h+=("<a onclick=\"stopBubble(event,"+data.id+")\" class=\"ico-shopping-cart\" href=\"javascript:; \"><img src=\"" + ctx + "/wesite/images/ico-shopping-cart.png\"' ></a>");
                        }else if(!isuserauth) {
                            h+=("<span class='price'><i class='a'>审核通过可见</i></span>");
                            h+=("<a onclick=\"stopBubble(event,"+data.id+")\" class=\"ico-shopping-cart\" href=\"javascript:; \"><img src=\"" + ctx + "/wesite/images/ico-shopping-cart.png\"' ></a>");
                        }else {
                            h+=("<span class='price'><i class='a'>不在本区域销售</i></span>");
                            h+=("<a  class=\"ico-shopping-cart\" href=\"javascript:; \"><img src=\"" + ctx + "/wesite/images/ico-shopping-cart-no.png\"' ></a>");
                        }
                        h+=("</li>");
                        panel.append(h);
                    }
                    nextsearchPageNo++;
                    $("#searchProductHolder").hide();
                    $("[name='pageno']").val(nextsearchPageNo)
                    return true;
                }
                nextsearchPageNo = 0;
                $("#searchProductHolder").text("已加载全部");
            }
        })
    }





    $(function(){

        $("[name='pageno']").val("1");
        loadsearch();

        var bottomHeight = $("div.bottom-nav").height()*2;

        var scroll = new auiScroll({
            listen:true, //是否监听滚动高度，开启后将实时返回滚动高度
            distance:bottomHeight //判断到达底部的距离，isToBottom为true
        },function(ret){
            if(ret.isToBottom){
                if(nextsearchPageNo>0){
                    loadsearch();
                }
            }
        });

    });







</script>

</html>